﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using JMT.Data;

namespace JMT.Shell
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        internal Data.JSolution _jSolution;
        internal JMSolutionStore _store;

        public MainWindow()
        {
            InitializeComponent();

            JMT.Controls.JUI.Init(this._ctlPropView, this._ctlDiagramContainer);

            _jSolution = new Data.JSolution();
            _jSolution.Id = Guid.NewGuid();
            _jSolution.Name = "NewSolution";
            JData.Current.Solution = _jSolution;

            Data.JClass jClass = JData.Current.AddModel<JClass>(_jSolution);

            Data.JDiagram jDiagram = JData.Current.AddModel<JDiagram>(_jSolution);

            _ctlTreeView.Bind(_jSolution);

            ShellCommand.Register(this);
            _ctlBtnSave.Command = ShellCommand.SaveCommand;
            _ctlBtnOpen.Command = ShellCommand.OpenCommand;
            _ctlBtnNew.Command = ShellCommand.NewCommand;

            JEventBus.GetInstance().Register("JMT.MODEL.ADD", _ctlTreeView);
            JEventBus.GetInstance().Register("JMT.MODEL.REMOVE", _ctlTreeView);
        }

        private void _ctlBtnAddRelation_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            string type = btn.Tag.ToString();
            this._ctlDiagramContainer.GetCurrent().BeginLink(type);
        }
    }
}
